package org.tote.controller;

import java.util.Map;

import javax.servlet.ServletContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.tote.service.user.UserService;

@Controller
public class HomeController implements BaseController {

	/*
	private static final String NEWS_LIST_COMMAND = "newsListCommand";
	private static final int NEWS_PER_PAGE = 10;
	public static final String NEWS_MAX_PAGE = "newsMaxPage";
	*/

	@Autowired
	UserService userService;

	//@Autowired
	//FeedbackService feedbackService;

	@Autowired
	ServletContext context;

	//@Autowired
	//private NewsService newsService;

	@RequestMapping("/")
	public String init(Map<String, Object> map) {
		// GrantedAuthority superAdminAutority = new SimpleGrantedAuthority(
		// Role.ADMINISTRATOR.toString());
		// if (SecurityContextHolder.getContext().getAuthentication()
		// .getAuthorities().contains(superAdminAutority)) {
		// return "redirect:/admin/user/list";
		// } else {
		// return "redirect:/home";
		// }
		return "redirect:/home";
	}

	@RequestMapping(value = "/home/{page}", method = RequestMethod.GET)
	public String initHomePage(@PathVariable int page, Map<String, Object> map) {

		/*
		List<NewsCommand> news = newsService.getNewsCommandPage(page, NEWS_PER_PAGE);
		boolean more = false;
		if (news.size() > NEWS_PER_PAGE) {
			more = true;
			news.subList(NEWS_PER_PAGE, news.size()).clear();
		}
		NewsListCommand newsListCommand = new NewsListCommand(news, page, more);
		int maxPage = newsService.getNewsMaxPage(NEWS_PER_PAGE);
		map.put(NEWS_LIST_COMMAND, newsListCommand);
		map.put(NEWS_MAX_PAGE, maxPage);
		*/

		return "home";
	}

	@RequestMapping(value = "/home", method = RequestMethod.GET)
	public String initHomePage(Map<String, Object> map) {
		return initHomePage(0, map);
	}

	@RequestMapping(value = "/feedback", method = RequestMethod.POST)
	public @ResponseBody
	void feedback(@RequestParam(value = "feedBackText") String text,
			@RequestParam(value = "page") String page) {
		//feedbackService.saveFeedback(text, page);
		return;
	}

	@RequestMapping(value = "/user", method = RequestMethod.GET)
	public String user(Map<String, Object> map) {
		return "user";
	}

	@RequestMapping(value = "/userMaintenancePage", method = RequestMethod.GET)
	public String userMaintenanceModePage(Map<String, Object> map) {
		return "userMaintenancePageLogin";
	}

	@RequestMapping(value = "/userMaintenancePage", method = RequestMethod.POST)
	public String userMaintenanceModePage2(Map<String, Object> map) {
		return "userMaintenancePageLogin";
	}

	@RequestMapping(value = "/userMaintenancePageLogout", method = RequestMethod.GET)
	public String userMaintenanceModePage3(Map<String, Object> map) {
		return "userMaintenancePageLogout";
	}

	@RequestMapping(value = "/userMaintenancePageLogout", method = RequestMethod.POST)
	public String userMaintenanceModePage4(Map<String, Object> map) {
		return "userMaintenancePageLogout";
	}

}
